import { toast } from 'nc-lightapp-front';
import { STATUS } from "../../constant";
import { fiterDefdoc, fiterLrzxOrg } from '../../../../common/util/fiterUtils';
/**
* @description: 表体编辑前事件
* @param: moduleId 区域编码
* @param: key 当前字段编码
* @return: 布尔 true表示可编辑
*/
export function beforeTableEvent(props, moduleId, key, value, index, record, status) {
    if (key == 'center' || key == 'ordercenter' || key == 'paycenter') {
        fiterLrzxOrg(props, moduleId, key, false, false);
        if(key == 'center'){
            props.cardTable.setValByKeyAndIndex('card_body', index, 'def1', { display: null, value: null});
        }
        
    } else if ('def3' == key) {
        let pk = props.cardTable.getValByKeyAndIndex(moduleId, index, 'def2').value;
        if (pk == '') {
            toast({ color: STATUS.warning, content: '请先维护报销类型！' });/* 国际化处理： 保存成功*/
            return false;
        } else {
            //设置费用明细数据
            let where = "def11 = '" + pk + "'";
            fiterDefdoc(props, moduleId, key, where);
        }
    }else if ('def1' == key) {
        let center = props.cardTable.getValByKeyAndIndex(moduleId, index, 'center').value;
        if (center == '') {
            toast({ color: STATUS.warning, content: '请先维护利润中心！' });/* 国际化处理： 保存成功*/
            return false;
        } else {
            //设置费用承担部门数据
            let where = "def1 in (select pk_org from org_orgs where dr=0 and name in (select name from org_orgs where pk_org='"+center+"')) and def7='Y'";
            fiterDefdoc(props, moduleId, key, where);
        }
    }

    return true;
}
